<template>
	<view class="content">
		<u-popup mode="bottom" v-model="isShowPriceGet" :closeable="isCloseable" border-radius="20">
			<view class="popup">
				<u-grid :col='2' :border='false'>
					<u-grid-item @click="toOurself">
						<u-icon name="photo" :size="80"></u-icon>
						<view class="grid-title">智通应收</view>
						<view class="grid-text">
							{{moneyTotal.sumInCome?'￥'+$options.filters["formatMoney"](moneyTotal.sumInCome)+'元':'暂无'}}
						</view>
					</u-grid-item>
					<u-grid-item @click="toOther">
						<u-icon name="lock" :size="80"></u-icon>
						<view class="grid-title">其他应收</view>
						<view class="grid-text">
							{{otherTotal.sumprice?'￥'+$options.filters["formatMoney"](otherTotal.sumprice)+'元':'暂无'}}
						</view>
					</u-grid-item>
				</u-grid>
			</view>
		</u-popup>
		<u-popup mode="bottom" v-model="isShowPricePay" :closeable="isCloseable" border-radius="20">
			<view class="popup">
				<u-grid :col='2' :border='false'>
					<u-grid-item @click="toOurself">
						<u-icon name="photo" :size="80"></u-icon>
						<view class="grid-title">智通应付</view>
						<view class="grid-text">
							{{moneyTotal.sumPay?'￥'+$options.filters["formatMoney"](moneyTotal.sumPay)+'元':'暂无'}}
						</view>
					</u-grid-item>
					<u-grid-item @click="toOther">
						<u-icon name="lock" :size="80"></u-icon>
						<view class="grid-title">其他应付</view>
						<view class="grid-text">
							{{otherTotal.sumPayPrice?'￥'+$options.filters["formatMoney"](otherTotal.sumPayPrice)+'元':'暂无'}}
						</view>
					</u-grid-item>
				</u-grid>
			</view>
		</u-popup>
		<u-notice-bar v-show="isShowNotice" style="width: 100%" mode="horizontal" :list="noticeList"></u-notice-bar>
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">
				智通大宗商务
			</text>
		</view>
		<u-grid :col='2' :border='false'>
			<u-grid-item name="item1" :index="0" @click="itemClick">
				<view class="icon">
					<img src="../../static/moneyA.png">
				</view>
				<view class="grid-title">历史应收</view>
				<view class="grid-text">
					{{moneyTotal.sumInCome+otherTotal.sumprice?'￥'+$options.filters["formatMoney"](moneyTotal.sumInCome+otherTotal.sumprice)+'元':'暂无'}}
				</view>
			</u-grid-item>
			<u-grid-item :index="1" @click="itemClick">
				<view class="icon">
					<img src="../../static/moneyB.png">
				</view>
				<view class="grid-title">历史应付</view>
				<view class="grid-text">
					{{moneyTotal.sumPay+otherTotal.sumPayPrice?'￥'+$options.filters["formatMoney"](moneyTotal.sumPay+otherTotal.sumPayPrice)+'元':'暂无'}}
				</view>
			</u-grid-item>
			<u-grid-item :index="2" @click="itemClick">
				<view class="icon">
					<img src="../../static/moneyC.png">
				</view>
				<view class="grid-title">手续费</view>
				<view class="grid-text">
					{{moneyTotal.sumHandingfee?'￥'+$options.filters["formatMoney"](moneyTotal.sumHandingfee)+'元':'暂无'}}
				</view>
			</u-grid-item>
			<u-grid-item :index="3" @click="itemClick">
				<view class="icon">
					<img src="../../static/moneyD.png">
				</view>
				<view class="grid-title">服务费</view>
				<view class="grid-text">
					{{moneyTotal.sumExpenseprice?'￥'+$options.filters["formatMoney"](moneyTotal.sumExpenseprice)+'元':'暂无'}}
				</view>
			</u-grid-item>
		</u-grid>
	</view>
</template>

<script>
	import {
		getPriceSum,
		getOtherSum
	} from '../../api/getlist.js'

	export default {
		data() {
			return {
				isShowNotice: true,
				index: 0,
				noticeList: ['重要通知 : 请前往货物货权仓储管理系统个人中心绑定手机号后授权登陆！'],
				queryParams: {},
				moneyTotal: {},
				otherTotal: {},
				isShowPriceGet: false,
				isShowPricePay: false,
				isCloseable: true,
			}
		},
		onPullDownRefresh() {
			this.getlist()
			uni.stopPullDownRefresh()
		},
		onLoad() {
			this.checkShow()
			this.getlist()
		},
		methods: {
			toOther() {
				getApp().globalData.swiperCurrent = 3
				uni.switchTab({
					url: "../detail/index"
				})
				this.isShowPriceGet = false
				this.isShowPricePay = false
			},
			toOurself() {
				getApp().globalData.swiperCurrent = 0
				uni.switchTab({
					url: "../detail/index"
				})
				this.isShowPriceGet = false
				this.isShowPricePay = false
			},
			checkShow() {
				this.isShowNotice = uni.getStorageSync('token') ? false : true
			},
			getlist() {
				if (uni.getStorageSync('token')) {
					getPriceSum().then(res => {
						if (res.data)
							this.moneyTotal = res.data
					})
					getOtherSum().then(res => {
						if (res.data)
							this.otherTotal = res.data
					})
				}
			},
			itemClick(index) {
				if (index === 0 || index === 1) {
					// getOtherSum().then(res => {
					// 	if (res.data)
					// 		this.otherTotal = res.data
					// })
					// getPriceSum().then(res => {
					// 	if (res.data)
					// 		this.moneyTotal = res.data
					// })
					this.isShowPriceGet = index === 0
					this.isShowPricePay = index === 1
				} else {
					getApp().globalData.swiperCurrent = (index - 1) < 0 ? 0 : (index - 1)
					uni.switchTab({
						url: "../detail/index"
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 40rpx;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 100rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		padding-bottom: 100rpx;
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 50rpx;
		font-weight: 700;
		color: $u-content-color;
	}

	.button-demo {
		margin-top: 80rpx;
	}

	.link-demo {
		margin-top: 80rpx;
	}

	.grid-title {
		font-size: 32rpx;
		margin-top: 4rpx;
		color: $u-type-info;
	}

	.grid-text {
		font-size: 28rpx;
		margin-top: 4rpx;
		color: $u-type-info;
	}

	.popup {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 600rpx;
	}

	.icon img {
		width: 80rpx;
		height: 80rpx;
	}
</style>
